package com.pet.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class RequestUtil {

    public static Map<String, Object> transToMAP(Map<String, String[]> parameterMap) {
        // 返回值Map
        Map<String, Object> returnMap = new HashMap<>();
        Iterator entries = parameterMap.entrySet().iterator();
        Map.Entry entry;
        String name = "";
        Object value = "";
        while (entries.hasNext()) {
            entry = (Map.Entry) entries.next();
            name = (String) entry.getKey();
            Object valueObj = entry.getValue();
            if(valueObj == null) continue;
            if (valueObj instanceof String[]) {
                String[] values = (String[]) valueObj;
                for (int i = 0; i < values.length; i++) {
                    value = values[i] + ",";
                }
                value = ((String)value).substring(0, ((String)value).length() - 1);
            } else {
                value = valueObj;
            }
            returnMap.put(name, value);
        }
        return returnMap;
    }
}
